package myky.com.doctorapp.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import myky.com.doctorapp.R;
import myky.com.doctorapp.api.Address;
import myky.com.doctorapp.entity.HomeArtiCalEntity;
import myky.com.doctorapp.utils.GlideRoundTransform;

public class HomeArticalAdapter extends BaseMultiItemQuickAdapter<HomeArtiCalEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public HomeArticalAdapter(List<HomeArtiCalEntity> data) {
        super(data);
        addItemType(HomeArtiCalEntity.IMAGITEM, R.layout.home_artcle_type_one);
        addItemType(HomeArtiCalEntity.NORMALCONTEN, R.layout.article_type_two);
    }

    @Override
    protected void addItemType(int type, int layoutResId) {
        super.addItemType(type, layoutResId);

    }

    @Override
    protected void convert(BaseViewHolder helper, HomeArtiCalEntity item) {
        switch (helper.getItemViewType()) {
            case HomeArtiCalEntity.IMAGITEM:
                ImageView imageView = helper.getView(R.id.artcalImg);
                helper.setText(R.id.content, item.getTitle());
                Glide.with(mContext).load(Address.IMAGE + item.getResource().get(0)).into(imageView);
                break;
            case HomeArtiCalEntity.NORMALCONTEN:
                ImageView helperView = helper.getView(R.id.artcalImg);
                Glide.with(mContext)
                        .load(Address.IMAGE + item.getResource().get(0))
                        .transform(new GlideRoundTransform(mContext))
                        .diskCacheStrategy(DiskCacheStrategy.RESULT)
                        .into(helperView);
                helper.setText(R.id.artcalTitle, item.getTitle());
                helper.setText(R.id.artcalCreatTime, item.getCreatetime());
                break;
            default:
                break;
        }

        helper.addOnClickListener(R.id.articalRootView);


    }
}